<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>类数组</title>
</head>

<body>

</body>
<script>
  /***
    let year = window.prompt("请输入年份: ");
    function isyear(year){
      // if(parseInt(year) % 4 === 0){
      //   return "闰年";
      // }else{
      //   return "不是闰年";
      // }

        return year % 4 === 0 ? "闰年" : "不是闰年"; 
    }
    console.log(isyear(year));
  */

  // 类数组

  let arr1 = [1, 2, 3];
  let arr2 = [4, 5, 6];
  console.log(arr1.concat(arr2));

  var obj = {
    "0": 1,
    "1": 2,
    "2": 3,
    "3": 4,
    "4": 5,
    "5": 6,
    "length": 6
  }
  Object.prototype.splice = Array.prototype.splice;
  Object.prototype.push = Array.prototype.push;

  obj.push(7);
  console.log(obj);


  // 数组去重
  Array.prototype.unique = function () {
    for (let i = 0; i < this.length; i++) {
      for (let j = 0; j < this.length - 1; j++) {
        if (this[i] == this[j]) {
          this.splice(j, 1);
        }
      }
    }
    return this;
  }

  var arr3 = [1, 1, 1, 2, 2, 2, 3, 3, 3];
  console.log(arr3.unique());

  //自定义typeof
  function My_typeof(val) {
    return Object.prototype.toString.call(val).split(" ")[1].split("]")[0];
  }
  var str = "str";
  console.log(My_typeof(str));

  var myarr = {
    0: 1,
    1: 2,
    2: 3,
    length: 3
  }
  const newArr = Array.from(myarr, function(item, index){
    return {
      student: this.person + item,
      order: index,
    }
  },{
    person: "NO."
  });
  console.log(newArr);
  // const data = newArr.map((item, index) => {
  //   return {
  //     student: "NO." + item,
  //     order: index
  //   }
  // })
  // console.log(data);

</script>

</html>